<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace api\api\controller;


use api\api\service\OrderService;
use cmf\controller\RestBaseController;
use api\api\service\IndexService;

class OrderController extends RestBaseController
{
    public function jpush_send()
    {
        $param = [
            'type' => 2,
            'registration_id' => '1a0018970adee39d3c7',
            'msg' => '你好'
        ];
        $res = hook_one('jpush_send', $param);
        $this->success("加载成功", $res);
    }
    /**
     * @api {post} user_order 乘车用户订单
     * @apiGroup Order
     *
     * @apiParam {String} token 参数说明.
     *
     * @apiSuccess {String} code 成功返回值.
     * @apiSuccess {String} msg  成功返回说明.
     * @apiSuccess {String} data  成功返回数据.
     *
     * @apiSuccessExample Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *      "code": 1,
     *      "msg": '获取成功'
     *      "data": ""
     *     }
     *
     * @apiError {String} code 错误返回值.
     * @apiSuccess {String} msg  错误返回说明.
     *
     * @apiErrorExample Error-Response:
     *     HTTP/1.1 404 Not Found
     *     {
     *         "code": '',
     *      "msg": '获取失败'
     *     }
     */
    public function user_order($type, $page)
    {
        $user_id = $this->getUserId();

        $orderservice = new OrderService();
        $order = $orderservice->user_order($user_id, $type, $page);

        if (count($order)) {
            foreach ($order as $k=>$v){
                $order[$k]['order_timefor']= date('Y-m-d h:i:s', $v['order_time']);
            }
            $this->success("加载成功", $order);
        } else {
            $this->error("加载完成!");
        }
    }

    /**
     * @api {post} order_task 订单定时任务（用于到期自动取消订单）
     * @apiGroup order
     *
     * @apiParam {String} token 参数说明.
     *
     * @apiSuccess {String} code 成功返回值.
     * @apiSuccess {String} msg  成功返回说明.
     * @apiSuccess {String} data  成功返回数据.
     *
     * @apiSuccessExample Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *      "code": 1,
     *      "msg": '获取成功'
     *      "data": ""
     *     }
     *
     * @apiError {String} code 错误返回值.
     * @apiSuccess {String} msg  错误返回说明.
     *
     * @apiErrorExample Error-Response:
     *     HTTP/1.1 404 Not Found
     *     {
     *         "code": '',
     *      "msg": '获取失败'
     *     }
     */
    public function order_task()
    {
        $orderservice = new OrderService();
        //订单取消
        $order= $orderservice->order_task();
        //订单分配
        $order= $orderservice->order_send();
        $this->success("加载成功", $order);
    }

	
	
	public function ceshi3($reservation_time)
	{
		$reservation_time = strtotime($reservation_time);
		$reservation_time = date('Y-m-d H:i', $reservation_time);
		$this->success("加载成功", $reservation_time);
		$indexService = new IndexService();
		$_line_money = $indexService->check_time_($reservation_time);
		if(!$_line_money){
			$this->error("此时间段请选择包车");
		}
		
	}
}
